package com.ehome.poct.core.dao.mybatis;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.core.util.BeanConvertUtil;
import com.ehome.poct.core.api.common.CellBoardStatus;
import com.ehome.poct.core.api.dto.check.CellBoardDTO;
import com.ehome.poct.core.dao.entity.check.CellBoardDO;
import com.ehome.poct.core.dao.mybatis.mapper.CellBoardMapper;
import com.ehome.poct.core.repository.check.CellBoardRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

/**
 * 血常规 板子耗材数据库仓储层
 * @author cq
 * @since 2022/03/08
 */
@Repository
public class CellBoardRepositoryImpl implements CellBoardRepository {
    @Autowired
    CellBoardMapper boardMapper;

    @Override
    public CellBoardDTO getByBoardSno(String sno) {
       return BeanConvertUtil.convertBean(
               boardMapper.selectOne(Wrappers.<CellBoardDO>lambdaQuery()
                .eq(CellBoardDO::getBoardSno,sno).last(" limit 1")),CellBoardDTO.class);
    }

    /**
     * 修改板子状态
     * @param status
     * @param sno
     * @return
     */
   @Override
   public int updateStatus(CellBoardStatus status, String sno){
       return boardMapper.update(null, Wrappers.<CellBoardDO>lambdaUpdate().eq(CellBoardDO::getBoardSno, sno)
               .set(CellBoardDO::getBoardStatus, status.getType())
               .set(CellBoardDO::getUpdateTime, LocalDateTime.now()));
   }
}
